/*
 * Parse CMS Enveloped data
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#ifndef ENCLAVE_CMS_H
#define ENCLAVE_CMS_H

#include <sys/types.h>
#include "cms_comm.h"

#define ENVELOPED_VERSION               2
#define ENVELOPED_RECIPIENT_VERSION     2

/*
 * parse_response_enveloped_data() - Parse BER-encoded CMS Enveloped Data.
 * @ciphertext_for_recipient (input): The serialized CMS content.
 * @cipher_symm_key (output): The symmetric key received in the RecipientInfo structrue.
 * @symm_key_iv (output): The IV received in the EncryptedContent structure.
 * @cipher_text (output): The actual ciphertext present in the Encrypted Content.
 *
 * Context: Process context.
 *
 * Returns: The status of the operation.
 */
int parse_response_enveloped_data(const struct stream_buf *ciphertext_for_recipient,
                                  struct stream_buf *cipher_symm_key,
                                  struct stream_buf *symm_key_iv,
                                  struct stream_buf *cipher_text);

/*
 * response_cipher_decrypt() - Decrypt data using symmetric key obtained from
                                @parse_response_enveloped_data.
 * @cipher_text (input): The ciphertext to decrypt.
 * @plain_symm_key (input): The symmetric key.
 * @symm_key_iv (input): The IV.
 * @plain_text (output): The plaintext.
 *
 * Context: Process context.
 *
 * Returns: The status of the operation.
 */
int response_cipher_decrypt(struct stream_buf *cipher_text,
                            struct stream_buf *plain_symm_key,
                            struct stream_buf *symm_key_iv,
                            struct stream_buf *plain_text);

#endif
